package com.sunnada.edu.business.salaryManage.controller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sunnada.edu.business.salaryManage.service.RewardService;
import com.sunnada.edu.system.pub.common.BasicController;
import com.sunnada.edu.system.pub.common.Tree;
import com.sunnada.edu.system.pub.common.TreeMethods;
import com.sunnada.edu.system.pub.dao.Page;
import com.sunnada.edu.system.pub.service.PubMethods;
import com.sunnada.edu.system.pub.util.Utils;

/***
 * explain 模块控制类 
 * @author chs 2015-5-12
 * version 1.0
 */
@Controller
@RequestMapping("/rewardController")
public class RewardController extends BasicController{
	@Resource
	RewardService rewardService;
	
	/**奖惩申请回复首页*/
	@RequestMapping("/reward")
	public String reward(HttpServletRequest request) { 
		String rewardId=request.getParameter("moduleId");
		request.setAttribute("pathValue", PubMethods.getPathValue(rewardId));
		return "business/salaryManage/rewardApply";
	}
	
	/**获取奖惩类型*/
	@RequestMapping("/getRewardType")
	public void getRewardType(HttpServletRequest request,HttpServletResponse response) { 
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, null, params);
		List<?> list = rewardService.getRewardType(params);
		JSONObject json = new JSONObject();		
		json.put("list", list);
		printInfo(response,json);
	}
	
	/**获取奖惩等级*/
	@RequestMapping("/getRewardLevel")
	public void getRewardLevel(HttpServletRequest request,HttpServletResponse response) { 
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, null, params);
		List<?> list = rewardService.getRewardLevel(params);
		JSONObject json = new JSONObject();		
		json.put("list", list);
		printInfo(response,json);
	}
	
	/**奖惩申请获取工人*/
	@RequestMapping("/getWorker")
	public void getWorker(HttpServletRequest request,HttpServletResponse response) { 
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, null, params);
		Page page = new Page(); 
		page.setRowCount(rewardService.getWorkerCots(params));
		page.setPageMap(request, page, params);
		List<?> list = rewardService.findWorkers(params);
		JSONObject json = new JSONObject();		
		json.put("list", list);
		json.put("params", params); 
		printInfo(response,json);
	}
	/**奖惩申请获取工程项目*/
	@RequestMapping("/getProject")
	public void getProject(HttpServletRequest request,HttpServletResponse response) { 
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, null, params);
		Page page = new Page(); 
		page.setRowCount(rewardService.getProjectCots(params));
		page.setPageMap(request, page, params);
		List<?> list = rewardService.findProjects(params);
		JSONObject json = new JSONObject();		
		json.put("list", list);
		json.put("params", params); 
		printInfo(response,json);
	}
	
	/**根据id获取奖惩申请*/
	@RequestMapping("/getRewardApplyByRecid")
	public void getRewardApplyByRecid(HttpServletRequest request,HttpServletResponse response) { 
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, null, params);
		List<?> list = rewardService.getRewardApplyByRecid(params);
		JSONObject json = new JSONObject();		
		json.put("list", list);
		printInfo(response,json);
	}
	
	/**奖惩申请添加页面*/
	@RequestMapping("/rewardAdd")
	public String rewardAdd(HttpServletRequest request) { 
		return "business/customerreward/reward_add";
	}
	/**奖惩申请工人信息页面*/
	@RequestMapping("/pageWorker")
	public String pageWorker(HttpServletRequest request) {
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, null, params);
		request.setAttribute("projectId", params.get("projectId"));
		return "business/salaryManage/worker";
	}
	/**奖惩申请工程项目页面*/
	@RequestMapping("/pageProject")
	public String pageProject(HttpServletRequest request) { 
		return "business/salaryManage/project";
	}
	/**奖惩申请修改页面*/
	@RequestMapping("/rewardUpdate")
	public String rewardUpdate(HttpServletRequest request) { 
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, null, params);
		Map reward = rewardService.getRewardByRecId(params);
		request.setAttribute("reward", reward);
		return "business/customerreward/reward_update";
	}
	
	/**奖惩申请保存功能 */
	@RequestMapping("/saveRewardApply")
	public void saveRewardApply(HttpServletRequest request,HttpServletResponse response) { 
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, null, params);
		msg = rewardService.rewardAdd(params);
		printInfo(response,msg);
	}
	/**奖惩申请删除功能*/
	@RequestMapping("/rewardDelete")
	public void rewardDelete(HttpServletRequest request,HttpServletResponse response) { 
		HashMap<String, String> params = new HashMap<String, String>();
		String recIds = request.getParameter("recIds");
		params.put("recIds",Utils.getSqlSplitStr(recIds));
		msg = rewardService.rewardDel(params);		
		printInfo(response,msg);
	}

	/**根据id获取奖惩申请单流程的基本情况*/
	@RequestMapping("/getProcessConditionByrecid")
	public void getProcessConditionByrecid(HttpServletRequest request,HttpServletResponse response) { 
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, null, params);
		List<?> list = rewardService.getProcessConditionByrecid(params);
		JSONObject json = new JSONObject();		
		json.put("list", list);
		printInfo(response,json);
	}
	
	/**奖惩申请审核*/
	@RequestMapping("/audit")
	public void audit(HttpServletRequest request,HttpServletResponse response) { 
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, null, params);
		msg = rewardService.audit(params);		
		printInfo(response,msg);
	}

}
